package bar.dark.lee.budget;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.HashMap;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.LinearLayout.LayoutParams;
import bar.dark.lee.BDConstents;
import bar.dark.lee.R;
import bar.dark.lee.SuperActivity;
import bar.dark.lee.common.BDUtil;
import bar.dark.lee.common.DBSQLite;
import bar.dark.lee.common.DBSQLite.ParseSelectData;
import bar.dark.lee.setting.TipInfoActivity;
import bar.dark.lee.setting.TipsActivity;
import bar.dark.lee.stats.StatsActivity;
import bar.dark.lee.stats.StatsCategoryActivity;
import bar.dark.lee.stats.StatsCategoryData;

public class BudgetActivity extends SuperActivity
{
	public static String BUDGET_YEAR = "budget_year";
	public static String BUDGET_MONTH = "budget_month";
	public static String BUDGET_DATE = "budget_day";
	
	private DBSQLite sql;
	
	private View dangerView;
	private TextView dangerTextView;
	
	private View leftDateButton;
	private View rightDateButton;
	private TextView dateTextView;
	
	private TextView moneyTextView;
	
	private TextView totalMoneyTextView;
	
	private TextView outMoneyTextView;
	
	private View listButton;
	
	private Button nextMonthButton;
	
	private Button insertButton;
	
	private int year;
	private int month;
	private int date;
	
	private int tempYear;
	private int tempMonth;
	private int tempDate;
	
	private ArrayList<StatsCategoryData> outList;
	private ArrayList<BudgetData> totalList;
	
	private int avgCount;
	private int percent;
	
	private BigDecimal totalMoney;
	private BigDecimal outMoney;
	
	private int startDate;
	
	private String toDate = "";
	
	private int budgetCount;
	
	private int budgetNextCount;
	
	private String budgets;
	
	private int flag;
	
	private String tableName = "";
	
	private TextView totalTextView;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		
		sql = DBSQLite.getInstance(superContext);
		
		setContentView(R.layout.budget_activity);
		
		setGoneTitle();
		
		setFindView();
		setOnClickListener();
		
		Intent intent = getIntent();
		
		flag = intent.getIntExtra(BudgetTabActivity.BUDGET_FLAG, 0);
		
		if (flag == BudgetTabActivity.OUT_FLAG)
		{
			totalTextView.setText("총 지출");
			tableName = "budget_category";
		}
		else if (flag == BudgetTabActivity.IN_FLAG)
		{
			totalTextView.setText("총 수입");
			tableName = "budget_in_category";
		}
		else if (flag == BudgetTabActivity.MOVE_FLAG)
		{
			totalTextView.setText("총 이동");
			tableName = "budget_move_category";
		}
		
		Calendar cal = Calendar.getInstance();
		year = cal.get(Calendar.YEAR);
		month = cal.get(Calendar.MONTH);
		date = cal.get(Calendar.DAY_OF_MONTH);
		
		// 달 시작일 가져온다
    	SharedPreferences pref = getSharedPreferences("pref", Activity.MODE_PRIVATE);
    	startDate = Integer.parseInt(pref.getString(BDConstents.START_DATE, "1"));
    	
    	// 시작일에 따라서 날짜 셋팅
		if (date < startDate)
		{
    		if (month == 0)
			{
				year--;
				month = 11;
			}
    		else
    		{
    			month--;
    		}
    		
			if (month < 9)
			{
				toDate = year + "0" + (month+1);
			}
			else
			{
				toDate = year + "" + (month+1);
			}
		}
		else
		{
			if (month < 9)
			{
				toDate = year + "0" + (month+1);
			}
			else
			{
				toDate = year + "" + (month+1);
			}
		}
    	
    	sql.selectMapTile(superContext, "SELECT * FROM " + tableName + " WHERE count = 0;", 
    			new ParseSelectData()
		{
			@Override
			public void resultData(Cursor c)
			{
				c.moveToFirst();
				
				if (c.getCount() > 0)
				{
					HashMap<String, String> map = new HashMap<String, String>();
					map.put("count", "201207");
					
					String [] whereArgs = new String[]{"0"};
					
					sql.update(superContext, tableName, map, "count = ?", whereArgs);
				}
			}
		});
	}
	
	@Override
	protected void onResume()
	{
		super.onResume();
		
		new ShowDialog().execute(BDUtil.asyncFlag, 0);
	}
	
	private void setFindView()
	{
		dangerView = findViewById(R.id.budgetDangerView);
		dangerTextView = (TextView) findViewById(R.id.budgetDangerTextView);
		
		leftDateButton = findViewById(R.id.budgetDateLeftButton);
		rightDateButton = findViewById(R.id.budgetDateRightButton);
		dateTextView = (TextView) findViewById(R.id.budgetDateText);
		
		moneyTextView = (TextView) findViewById(R.id.budgetMoneyTextView);
		totalMoneyTextView = (TextView) findViewById(R.id.budgetTotalMoneyTextView);
		outMoneyTextView = (TextView) findViewById(R.id.budgetOutMoneyTextView);
		
		listButton = findViewById(R.id.budgetListButton);
		
		nextMonthButton = (Button) findViewById(R.id.budgetNextMonthButton);
		
		insertButton = (Button) findViewById(R.id.budgetInsertButton);
		
		totalTextView = (TextView) findViewById(R.id.budgetTotalFlagTextView);
	}
	
	private void setOnClickListener()
	{
		leftDateButton.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				startLeftMonthButton();
			}
		});
		
		rightDateButton.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				startRightMonthButton();
			}
		});
		
		listButton.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Intent intent = new Intent(superContext, BudgetListActivity.class);
				intent.putExtra(BudgetTabActivity.BUDGET_FLAG, flag);
				intent.putExtra(BUDGET_YEAR, year);
				intent.putExtra(BUDGET_MONTH, month);
				intent.putExtra(BUDGET_DATE, date);
				startActivity(intent);
			}
		});
		
		nextMonthButton.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				if (totalList.size() < 1)
				{
					BDUtil.showDialog(superContext, "알림", "다음달로 적용 시킬 예산이 하나도 없습니다.");
					return;
				}
				
				new ShowDialog().execute(BDUtil.asyncFlag, 1);
			}
		});
		
		insertButton.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Intent intent = new Intent(superContext, BudgetInsertActivity.class);
				intent.putExtra(BudgetTabActivity.BUDGET_FLAG, flag);
				intent.putExtra(BUDGET_YEAR, year);
				intent.putExtra(BUDGET_MONTH, month);
				intent.putExtra(BUDGET_DATE, date);
				startActivity(intent);
			}
		});
	}
	
	private void setData()
	{
		String firstDate = "";
    	String lastDate = "";
		
		if (startDate == 1) 
		{
			firstDate = BDUtil.getDateDB(year, month+1, 00);
			lastDate = BDUtil.getDateDB(year, month+1, 32);
		}
		else
		{
			if (month+1 == 1)
			{
				firstDate = BDUtil.getDateDB(year, 1, startDate);
				lastDate = BDUtil.getDateDB(year, 2, startDate-1);
			}
			else if (month+1 == 12)
			{
				firstDate = BDUtil.getDateDB(year, 12, startDate);
				lastDate = BDUtil.getDateDB(year+1, 1, startDate-1);
			}
			else
			{
				firstDate = BDUtil.getDateDB(year, month+1, startDate);
				lastDate = BDUtil.getDateDB(year, month+2, startDate-1);
				
			}
		}
		
		totalList = new ArrayList<BudgetData>();
		
		sql.selectMapTile(superContext, "SELECT * FROM " + tableName + " WHERE count = " 
						+ toDate + ";", new ParseSelectData()
		{
			@Override
			public void resultData(Cursor c)
			{
				int idIdx = c.getColumnIndex("id");
				int nameIdx = c.getColumnIndex("name");
				int moneyIdx = c.getColumnIndex("money");
				int countIdx = c.getColumnIndex("count");
				int linkidIdx = c.getColumnIndex("linkid");
				
				c.moveToFirst();
				
				for (int i = 0; i < c.getCount(); i++)
				{
					BudgetData data = new BudgetData();
					
					data.setId(c.getInt(idIdx) + "");
					data.setName(c.getString(nameIdx));
					data.setMoney(c.getString(moneyIdx));
					data.setCount(c.getString(countIdx));
					data.setLinkid(c.getString(linkidIdx));
					
					totalList.add(data);
					c.moveToNext();
				}
			}
		});
		
		outList = new ArrayList<StatsCategoryData>();
		
		for (int i = 0; i < totalList.size(); i++)
		{
			String category = totalList.get(i).getName();
			
			if (flag == BudgetTabActivity.OUT_FLAG)
			{
				String categoryQuery = "SELECT category, SUM(outmoney" + 
						") omoney, SUM(postmoney) pmoney FROM in_out WHERE " +
						"category = '" + BDUtil.getApostrophe(category) + "' and " +
						"inmoney in ('0') and (outmoney not in ('0') or postmoney not in ('0')) and date >= " +
						firstDate + " and date <= " +
						lastDate + " and type not in (" + 
						BDConstents.INOUT_TYPE + ", " +
						BDConstents.OUTIN_TYPE + ", " +
						BDConstents.MYBANK_INOUT_TYPE + ") " +
						"GROUP BY category "
						+ "UNION ALL "
						+ "SELECT category, SUM(outmoney" + 
						") omoney, SUM(postmoney) pmoney FROM in_out WHERE " +
						"category = '" + BDUtil.getApostrophe(category) + "' and " +
						"date >= " +
						firstDate + " and date <= " +
						lastDate + " and category in ('" 
						+ BDConstents.CATEGORY_SUSUMONEY + "') GROUP BY category;";
				
				sql.selectMapTile(this, categoryQuery, new ParseSelectData()
				{
					@Override
					public void resultData(Cursor c)
					{
						int categoryIdx = c.getColumnIndex("category");
						int moneyIdx = c.getColumnIndex("omoney");
						int pmoneyIdx = c.getColumnIndex("pmoney");
						
						BigDecimal money = BigDecimal.ZERO;
						BigDecimal pmoney = BigDecimal.ZERO;
						String name = "";
											
						c.moveToFirst();
						
						for (int i = 0; i < c.getCount(); i++)
						{
							StatsCategoryData data = new StatsCategoryData();
							name = c.getString(categoryIdx);
							money = new BigDecimal(c.getString(moneyIdx));
							pmoney = new BigDecimal(c.getString(pmoneyIdx));
							data.setCategory(name);
							data.setMoney(money.add(pmoney).toString());
							outList.add(data);
							
							c.moveToNext();
						}
					}
				});
			}
			else if (flag == BudgetTabActivity.IN_FLAG)
			{
				String categoryQuery = "SELECT category, SUM(inmoney) imoney FROM in_out WHERE " +
						"category = '" + BDUtil.getApostrophe(category) + "' and " +
						"inmoney not in ('0') and date >= " +
						firstDate + " and date <= " +
						lastDate + " and type not in (" + 
						BDConstents.INOUT_TYPE + ", " +
						BDConstents.OUTIN_TYPE + ", " +
						BDConstents.MYBANK_INOUT_TYPE + ") " +
						"and category not in ('" + 
						BDConstents.CATEGORY_POST_OUT +
						"') GROUP BY category;";
				
				sql.selectMapTile(this, categoryQuery, new ParseSelectData()
				{
					@Override
					public void resultData(Cursor c)
					{
						int categoryIdx = c.getColumnIndex("category");
						int moneyIdx = c.getColumnIndex("imoney");
						
						BigDecimal money = BigDecimal.ZERO;
						String name = "";
											
						c.moveToFirst();
						
						for (int i = 0; i < c.getCount(); i++)
						{
							StatsCategoryData data = new StatsCategoryData();
							name = c.getString(categoryIdx);
							money = new BigDecimal(c.getString(moneyIdx));
							data.setCategory(name);
							data.setMoney(money.toString());
							outList.add(data);
							
							c.moveToNext();
						}
					}
				});
			}
			else if (flag == BudgetTabActivity.MOVE_FLAG)
			{
				String inOutQuery = "SELECT category, SUM(outmoney) omoney, SUM(postmoney) pmoney " +
						"FROM in_out WHERE date >= " +
						firstDate + " and date <= " +
						lastDate + " and " +
						"category = '" + BDUtil.getApostrophe(category) + "' and " +
						"type = " + BDConstents.INOUT_TYPE + 
						" GROUP BY category;";
				
				sql.selectMapTile(this, inOutQuery, new ParseSelectData()
				{
					@Override
					public void resultData(Cursor c)
					{
						int categoryIdx = c.getColumnIndex("category");
						int omoneyIdx = c.getColumnIndex("omoney");
						int pmoneyIdx = c.getColumnIndex("pmoney");
						
						BigDecimal omoney = BigDecimal.ZERO;
						String name = "";
											
						c.moveToFirst();
						
						for (int i = 0; i < c.getCount(); i++)
						{
							StatsCategoryData data = new StatsCategoryData();
							name = c.getString(categoryIdx);
							omoney = new BigDecimal(c.getString(omoneyIdx));
							omoney = omoney.add(new BigDecimal(c.getString(pmoneyIdx)));
							data.setCategory(name);
							
							data.setMoney(omoney.toString());
							outList.add(data);
							
							c.moveToNext();
						}
					}
				});
				
				inOutQuery = "SELECT category, SUM(inmoney) imoney " +
						"FROM in_out WHERE date >= " +
						firstDate + " and date <= " +
						lastDate + " and " +
						"category = '" + BDUtil.getApostrophe(category) + "' and " +
						"type = " +	BDConstents.OUTIN_TYPE + 
						" GROUP BY category;";
				
				sql.selectMapTile(this, inOutQuery, new ParseSelectData()
				{
					@Override
					public void resultData(Cursor c)
					{
						int categoryIdx = c.getColumnIndex("category");
						int imoneyIdx = c.getColumnIndex("imoney");
						
						BigDecimal imoney = BigDecimal.ZERO;
						String name = "";
											
						
						c.moveToFirst();
						
						for (int i = 0; i < c.getCount(); i++)
						{
							StatsCategoryData data = new StatsCategoryData();
							name = c.getString(categoryIdx);
							imoney = new BigDecimal(c.getString(imoneyIdx));
							data.setCategory(name);
							
							data.setMoney(imoney.toString());
							
							boolean flag = false;
							
							for (int j = 0; j < outList.size(); j++)
							{
								if (data.getCategory().equals(outList.get(j).getCategory()))
								{
									BigDecimal tempMoney = new BigDecimal(outList.get(j).getMoney());
									
									outList.get(j).setMoney(tempMoney.add(new BigDecimal(data.getMoney())).toString());
									
									flag = true;
								}
							}
							
							if (flag == false)
							{
								outList.add(data);
							}
							
							c.moveToNext();
						}
					}
				});
				
				inOutQuery = "SELECT type, category, SUM(outmoney) omoney, " +
						"SUM(inmoney) imoney, SUM(postmoney) pmoney " +
						"FROM in_out WHERE date >= " +
						firstDate + " and date <= " +
						lastDate + " and " +
						"category = '" + BDUtil.getApostrophe(category) + "' and " +
						"type = " +	BDConstents.MYBANK_INOUT_TYPE + 
						" GROUP BY category;";
				
				sql.selectMapTile(this, inOutQuery, new ParseSelectData()
				{
					@Override
					public void resultData(Cursor c)
					{
						int categoryIdx = c.getColumnIndex("category");
						int omoneyIdx = c.getColumnIndex("omoney");
						int pmoneyIdx = c.getColumnIndex("pmoney");
						int imoneyIdx = c.getColumnIndex("imoney");
						
						BigDecimal omoney = BigDecimal.ZERO;
						BigDecimal pmoney = BigDecimal.ZERO;
						BigDecimal imoney = BigDecimal.ZERO;
						String name = "";
											
						c.moveToFirst();
						
						for (int i = 0; i < c.getCount(); i++)
						{
							StatsCategoryData data = new StatsCategoryData();
							name = c.getString(categoryIdx);
							omoney = new BigDecimal(c.getString(omoneyIdx));
							pmoney = new BigDecimal(c.getString(pmoneyIdx));
							imoney = new BigDecimal(c.getString(imoneyIdx));
							data.setCategory(name);
							
							omoney = omoney.add(pmoney);
							
							data.setMoney(omoney.toString());
							
							boolean flag = false;
							
							for (int j = 0; j < outList.size(); j++)
							{
								if (data.getCategory().equals(outList.get(j).getCategory()))
								{
									BigDecimal tempMoney = new BigDecimal(outList.get(j).getMoney());
									
									outList.get(j).setMoney(tempMoney.add(new BigDecimal(data.getMoney())).toString());
									
									flag = true;
								}
							}
							
							if (flag == false)
							{
								outList.add(data);
							}
							
							c.moveToNext();
						}
					}
				});
			}
		}
	}
	
	private void startLeftMonthButton()
	{
		if (month == 0)
		{
			year--;
			month = 11;
		}
		else
		{
			month--;
		}
		
		BDUtil.startLeftDegrees(dateTextView).setAnimationListener(new AnimationListener()
		{
			@Override
			public void onAnimationStart(Animation animation)
			{
			}
			
			@Override
			public void onAnimationRepeat(Animation animation)
			{
			}
			
			@Override
			public void onAnimationEnd(Animation animation)
			{
				if (month < 9)
				{
					toDate = year + "0" + (month+1);
				}
				else
				{
					toDate = year + "" + (month+1);
				}
				
				new ShowDialog().execute(BDUtil.asyncFlag, 0);
			}
		});
	}	
	
	private void startRightMonthButton()
	{
		if (month == 11)
		{
			year++;
			month = 0;
		}
		else
		{
			month++;
		}
		
		BDUtil.startRightDegrees(dateTextView).setAnimationListener(new AnimationListener()
		{
			@Override
			public void onAnimationStart(Animation animation)
			{
			}
			
			@Override
			public void onAnimationRepeat(Animation animation)
			{
			}
			
			@Override
			public void onAnimationEnd(Animation animation)
			{
				if (month < 9)
				{
					toDate = year + "0" + (month+1);
				}
				else
				{
					toDate = year + "" + (month+1);
				}
				
				new ShowDialog().execute(BDUtil.asyncFlag, 0);
			}
		});
	}
	
	/**
	 * 다음달로 예산을 적용 시킨다.
	 */
	private void setNextMonthData()
	{
		budgetNextCount = 0;
		
		budgets = "";
		String tempToDate = "";
		
		int toYear = year;
		int toMonth = month;
		
		if (month == 11)
		{
			toYear++;
			toMonth = 0;
		}
		else
		{
			toMonth++;
		}
		
		if (toMonth < 9)
		{
			tempToDate = toYear + "0" + (toMonth+1);
		}
		else
		{
			tempToDate = toYear + "" + (toMonth+1);
		}
		
		for (int i = 0; i < totalList.size(); i++)
		{
			BudgetData data = totalList.get(i);
			
			if (getBudgetEn(data, tempToDate) < 1)
			{
				HashMap<String, String> map = new HashMap<String, String>();
				
				map.put("name", data.getName());
				map.put("money", data.getMoney());
				map.put("count", tempToDate);
				
				sql.insert(superContext, map, tableName);
				
				budgetNextCount++;
			}
			else
			{
				budgets += data.getName() + ", ";
			}
		}
		
		if (!budgets.equals(""))
		{
			budgets = budgets.substring(0, budgets.length()-2);
		}
	}
	
	/**
	 * 다음달에 적용 시킬 예산이 이미 있는지 없는지 체크
	 * @return
	 */
	private int getBudgetEn(BudgetData data, String tempTodate)
	{
		budgetCount = 0;
		
		sql.selectMapTile(superContext, "SELECT * FROM " + tableName +
				" WHERE name = '" + BDUtil.getApostrophe(data.getName()) + "'" +
				" and count = " + tempTodate + ";", 
				new ParseSelectData()
		{
			@Override
			public void resultData(Cursor c)
			{
				budgetCount = c.getCount();
			}
		});
		
		return budgetCount;
	}
	
	/**
	 * 다이얼로그 뛰우기 
	 */
	private class ShowDialog extends AsyncTask<Integer, Integer, Integer>{
		ProgressDialog dialog = null;
		
		@Override
		protected void onPreExecute() {
			super.onPreExecute();
			if (BDUtil.btnEnable)
			{
				BDUtil.btnEnable = false;
				BDUtil.asyncFlag = -1;
				
				dialog = new ProgressDialog(superContext);
				dialog.setCancelable(false);
				dialog.setMessage("Loading...");
				dialog.show();
			}
		}
		
		@Override
		protected Integer doInBackground(Integer... arg0) {
			
			if (arg0[0] == 0) 
			{
				if (arg0[1] == 0)
				{
					setData();
					
					return arg0[1];
				}
				else if (arg0[1] == 1)
				{
					try
					{
						sql.beginTansaction(superContext);
						
						setNextMonthData();
						
						sql.setTransactionSuccessful();
					} catch (Exception e)
					{
						return -1;
					} finally {
						try 
						{
							sql.endTransaction(superContext);
						} catch (Exception e) 
						{
							return -1;
						}
					}
					
					return arg0[1];
				}
				
				return arg0[0];
			}
			else
			{
				return arg0[0];
			}
		}

		@Override
		protected void onPostExecute(Integer result) {
			super.onPostExecute(result);
			
			if (dialog != null)
			{
				dialog.dismiss();
			}
			
			if (result == -1)
			{
				BDUtil.showDialog(superContext, "오류", "데이터 저장에 실패했습니다.");
			}
			else if (result == 0)
			{
				BDUtil.btnEnable = true;
				BDUtil.asyncFlag = 0;
				
				totalMoney = BigDecimal.ZERO;
				outMoney = BigDecimal.ZERO;
				
				for (int i = 0; i < outList.size(); i++)
				{
					outMoney = outMoney.add(new BigDecimal(outList.get(i).getMoney()));
				}
				
				for (int i = 0; i < totalList.size(); i++)
				{
					totalMoney = totalMoney.add(new BigDecimal(totalList.get(i).getMoney()));
				}
				
				avgCount = (int)(((double)Math.abs(outMoney.doubleValue()) 
						/ (double)(totalMoney.doubleValue())) * 100);
				
//				percent = 50 + (avgCount/2);
				
				percent = avgCount;
				
				LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, LayoutParams.FILL_PARENT);
				
				if ((int)percent > 100)
				{
					params.weight = 100;
				}
				else
				{
					params.weight = percent;
				}
				
				dangerView.setLayoutParams(params);
				dangerTextView.setText(((int)percent) + "%");
				
				totalMoneyTextView.setText(BDUtil.getWon(totalMoney.toString()) + shape);
				outMoneyTextView.setText(BDUtil.getWon(outMoney.toString()) + shape);
				
				moneyTextView.setText(BDUtil.getWon(totalMoney.subtract(outMoney).toString()) + shape);
				
//				if (totalMoney.subtract(outMoney).compareTo(BigDecimal.ZERO) > 0)
//				{
//					moneyTextView.setText(totalMoney.subtract(outMoney).toString() + shape);
//				}
//				else
//				{
//					moneyTextView.setText("0" + shape);
//				}
				
				// 시작일에 따라서 날짜 셋팅
				if (startDate == 1)
				{
		    		dateTextView.setText(year + "년 " + (month+1) + "월");
				}
		    	else if (date < startDate)
				{
		    		tempYear = year;
		    		tempMonth = month;
		    		tempDate = date;
		    		
		    		if (month == 11)
		    		{
		    			tempYear++;
		    			tempMonth = 0;
		    		}
		    		else
		    		{
		    			tempMonth++;
		    		}
		    		
					dateTextView.setText(year + "년 " + (month+1) + "월 ~ " 
									+ tempYear + "년 " + (tempMonth+1) + "월");
				}
				else
				{
					tempYear = year;
		    		tempMonth = month;
		    		tempDate = date;
		    		
		    		if (month == 11)
		    		{
		    			tempYear++;
		    			tempMonth = 0;
		    		}
		    		else
		    		{
		    			tempMonth++;
		    		}
					
		    		dateTextView.setText(year + "년 " + (month+1) + "월 ~ " 
							+ tempYear + "년 " + (tempMonth+1) + "월");
				}
			}
			else if (result == 1)
			{
				if (budgets.equals(""))
				{
					BDUtil.showDialog(superContext, "알림", "이번달 예산이 다음달로 총 " + budgetNextCount 
							+ "개 적용 되었습니다.");
				}
				else
				{
					BDUtil.showDialog(superContext, "알림", "이번달 예산이 다음달로 총 " + budgetNextCount 
							+ "개 적용 되었습니다. " + budgets + "는 이미 있어서 적용 하지 못하였습니다.");
				}
			}
		}
	}

	@Override
	protected void tipButton()
	{
		Intent intent = new Intent(this, TipInfoActivity.class);
		intent.putExtra(TipsActivity.TIP_REQUEST_KEY, TipsActivity.TIP_BUDGET);
		startActivity(intent);
	}

}
